/**
 * Copyright &copy; 2015-2020 <a href="www.dsesa.cn/">ESA</a> All rights reserved.
 */
package com.jeeplus.modules.actSetting.service;

import com.jeeplus.common.utils.IdGen;
import com.jeeplus.core.persistence.Page;
import com.jeeplus.core.service.CrudService;
import com.jeeplus.modules.actSetting.entity.ActSetting;
import com.jeeplus.modules.actSetting.mapper.ActSettingMapper;
import com.jeeplus.modules.sys.entity.Role;
import com.jeeplus.modules.sys.service.SystemService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.UUID;

/**
 * 数据字典Service
 * @author lgf
 * @version 2017-01-16
 */
@Service
@Transactional(readOnly = true)
public class ActSettingService extends CrudService<ActSettingMapper, ActSetting> {

	@Autowired
	private ActSettingMapper actSettingMapper;

	@Autowired
	private SystemService systemService;

	/**
	 * 添加款项
	 */
	@Transactional(readOnly = false)
	public boolean setRole(String procDefId,String procDefkey,String roleId) {
        ActSetting actSetting = new ActSetting();
		Role role = systemService.getRole(roleId);
		if(role != null){
			actSetting.setGroupId(role.getEnname());
			actSetting.setProcDefId(procDefId);
			actSetting.setRoleId(roleId);
			actSetting.setProcDefkey(procDefkey);
			actSetting.setId(IdGen.uuid());
			int i = actSettingMapper.insertRole(actSetting);
			if(i > 0){
				return true;
			}else {
				return false;
			}
		}else {
			return false;
		}



	}

    /**
     * 根据objectId获取档案对应的款项
     * @param objectId
     * @return
     */
	@Transactional(readOnly = false)
    public List<ActSetting> getRoleList(String objectId){
	    ActSetting actSetting = new ActSetting();
        actSetting.setProcDefId(objectId);
	    return actSettingMapper.findList(actSetting);
    }

	@Transactional(readOnly = false)
	public void delete(String id) {
	    actSettingMapper.deleteRole(id);
	}

	@Transactional(readOnly = false)
	public void auth() {
	   actSettingMapper.auth();
	}

    public Page<ActSetting> findPage(Page<ActSetting> page, ActSetting actSetting) {
        return super.findPage(page, actSetting);
    }


}
